<template>
  <el-select :value="currentVal" multiple placeholder="请选择名单" :style="{ 'width': width }" clearable @change="change">
    <el-option v-for="(item, index) in data" :key="index" :label="item.title" :value="item.id" :disabled="!item.status" />
  </el-select>
</template>

<script>
/**
 * 业务组件 - 黑名单
 */
export default {
  name: 'Blacklist',
  props: {
    /** 数据源 */
    value: {
      type: String,
      default: ''
    },
    /** 宽度 */
    width: {
      type: String,
      default: '120px'
    }
  },
  data() {
    return {
      api: this.$u.api.PluginsBlacklist,
      data: [],
      currentVal: []
    }
  },
  watch: {
    // 监听数据
    value: {
      immediate: true,
      handler(val) {
        if (val) {
          this.currentVal = val.split(',')
        } else {
          this.currentVal = []
        }
      }
    }
  },
  created() {
    // 初始化数据
    this.initData()
  },
  methods: {
    // 初始化数据
    initData() {
      this.api.data().then(res => {
        this.data = res.data
      })
    },
    change(ids) {
      this.$emit('input', ids.toString())
    }
  }
}
</script>

<style lang="scss" scoped>
::v-deep{
  .el-input{
    width: 100% !important;
  }
}
</style>
